#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[200001],h[200001],n,ans;
void dfs(int x,int sum){
//	cout<<1;
	if(x>n){
		ans=max(ans,sum);
		return ;
	}
	h[x]=1;
	int y=x-1;
	while(h[y]==2) y--;
	if(a[y]==a[x]) dfs(x+1,sum+a[x]);
	else dfs(x+1,sum);
	y=x-1;
	h[x]=2;
	while(h[y]==1) y--;
	if(a[y]==a[x]) dfs(x+1,sum+a[x]);
	else dfs(x+1,sum);
	return ;
}
main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	int t;
	cin>>t;
	while(t){
		cin>>n;
		for(int i=1;i<=n;i++) cin>>a[i];
		dfs(1,0);
		t--;
		cout<<ans<<endl;
		ans=0;
	}
	return 0;
}
